package cn.hicard.risk.task;

import java.util.TimerTask;

import org.apache.log4j.Logger;

import cn.hicard.risk.common.Constant;
import cn.hicard.risk.action.webpay.TransMonitorFlex;
import cn.hicard.risk.service.webpay.TransMonitorService;
import cn.hicard.util.SpringContext;

/**
 * 成功率统计定时器任务类
 * @author yangzhou
 *
 */
public class SuccessRateStatisticsTask extends TimerTask {
	
	/** 日志记录工具 */
	private static Logger logger = Logger.getLogger(Constant.LOGGER_MAIN);

	private TransMonitorService transMonitorService;
	private TransMonitorFlex transMonitorFlex;
	
	/**
	 * 初始化操作，由于定时器是由系统自动执行，而非户请求操作，
	 * 因此需要使用的业务类不会被Spring初始化需要手动执行初始化。
	 */
	private void initialize(){
		
		if(transMonitorService == null){
			transMonitorService = (TransMonitorService) SpringContext.getBean("transMonitorService");
		}
		
		if(transMonitorFlex == null){
			transMonitorFlex = new TransMonitorFlex();
			transMonitorFlex.setTransMonitorService(transMonitorService);
		} 
	}
	
	@Override
	public void run() {
		// 调用初始化
		initialize();
		try {
			transMonitorFlex.successRateStatistics("", "");
		} catch (Exception e) {
			logger.error("调用成功率统计自动任务失败", e);
		}
	}
}
